package com.sample.transaction.seata.sys.controller;

import cn.hutool.core.util.RandomUtil;
import com.sample.transaction.seata.sys.entity.Order;
import com.sample.transaction.seata.sys.repo.OrderRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OrderController {

    private final OrderRepository orderRepository;

    // http://localhost:4001/order/insert
    @GetMapping("insert")
    public Boolean getUserById(){
        Order order = new Order();
        order.setUserId(RandomUtil.randomString(10));
        order.setCommodityCode(RandomUtil.randomString(10));
        order.setCount(RandomUtil.randomInt(5));
        order.setMoney(RandomUtil.randomInt(3));
        orderRepository.save(order);
        return Boolean.TRUE;
    }

}
